home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Devices & Hardware / NuBus⁄Slot Manager / Slot Tools / crcPatch folder / CRCPatch (MPW 2.02) / CRCPatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  2.8 KB  |  105 lines  |  [TEXT/MPS ]

  1.  
  2.  
  3. /**********************************************************************
  4.  *
  5.  * Copyright Apple Computer, Inc. 1986
  6.  * All Rights Reserved
  7.  *
  8.  *    crcPatch        : This program reads the code segment 1 from
  9.  *                        the Resource file and calculates the crc value.
  10.  *                        It then patches the file and saves it.
  11.  *
  12.  *    Author            : xxxxxx xxxxxx, July 30, 1986.
  13.  *
  14.  *    Mod History        : Nil.
  15.  *
  16.  **********************************************************************/
  17.                         
  18.  
  19. #include <stdio.h>
  20. #include <types.h>
  21. #include <osutils.h>
  22. #include <files.h>
  23. #include <resources.h>
  24. #include <memory.h>
  25. #include <errno.h>
  26.  
  27.  
  28. pascal void debugger() extern 0xa9ff;
  29.  
  30.  
  31. pascal void _CalcCRC (SizeCode,CodePtr,crc)
  32. long        SizeCode;
  33. Ptr            CodePtr;
  34. long        *crc;
  35. extern;
  36.  
  37. /******************************************************************
  38.     Main
  39. *******************************************************************/
  40. main(argc,argv)
  41.  
  42. int      argc;
  43. char  *argv[];
  44.  
  45. {
  46.   short        refnum;
  47.   Handle    CodeHandle;        /* Handle to code resource */
  48.   short        IOR;            /* IO Result */
  49.   long        SizeCode;        /* Size of the code */
  50.   Ptr        CodePtr;        /* Pointer to the code */
  51.   long        crc;            /* the crc value */
  52.         
  53.   if (argc == 1)
  54.     {
  55.       fprintf(stderr,"### ERROR : No input file specified.\n");
  56.       fprintf(stderr,"### SYNTAX: crcPatch  filename\n");
  57.       fprintf(stderr,"### DSCRPT: Calculate and patch the crc value to code segment 1.\n");
  58.     }
  59.   else if (argc != 2)
  60.     {
  61.       fprintf(stderr,"### ERROR : Wrong number of parameters specified.\n");
  62.       fprintf(stderr,"### SYNTAX: crcPatch  filename\n");
  63.       fprintf(stderr,"### DSCRPT: Calculate and patch the crc value to code segment 1.\n");
  64.     }
  65.   else
  66.     {
  67.       refnum = OpenResFile(argv[1]);
  68.       if (refnum < 0 )
  69.         fprintf(stderr,"### ERROR : Resource file: %s can't be opened. err = %d.\n",argv[1],refnum);
  70.       else
  71.         {
  72.            CodeHandle = GetResource('CODE',1);
  73.            HLock(CodeHandle);
  74.            IOR = ResError();
  75.            if (IOR != 0)
  76.              fprintf(stderr,"### ERROR : Code resource not available. Err = %d\n",IOR);
  77.            else
  78.              {
  79.               /* SizeCode = SizeResource(CodeHandle);*/
  80.                SizeCode = GetHandleSize(CodeHandle);
  81.                SizeCode = SizeCode - 4;                                        /* Skip first 4 bytes (Resource header) */               
  82.                CodePtr = (Ptr) ( ((long) *CodeHandle) & 0x0FFFFFF) + 4;        /* Skip first 4 bytes (Resource header) */
  83.         
  84.                _CalcCRC(SizeCode,CodePtr,&crc);                                /* Calc and patch the crc value */
  85.  
  86.                ChangedResource(CodeHandle);
  87.                IOR = ResError();
  88.                if (IOR != 0)
  89.                  fprintf(stderr,"### ERROR : ChangedResource. Err = %d\n",IOR);
  90.  
  91.                WriteResource(CodeHandle);
  92.                IOR = ResError();
  93.                if (IOR != 0)
  94.                  fprintf(stderr,"### ERROR : WriteResource. Err = %d\n",IOR);
  95.  
  96.                CloseResFile(refnum);
  97.                IOR = ResError();
  98.                if (IOR != 0)
  99.                  fprintf(stderr,"### ERROR : CloseResFile. Err = %d\n",IOR);
  100.              }
  101.         }
  102.     }
  103. }
  104.  
  105.